package com.fg.pro.trade.controller;



import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.trade.service.TradeSaleService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;


/**
 * 销售报表信息(TradeSale)表控制层
 *
 * @author makejava
 * @since 2025-08-28 10:00:40
 */
@RestController
@RequestMapping("tradeSale")
public class TradeSaleController {
    /**
     * 服务对象
     */
    @Resource
    private TradeSaleService tradeSaleService;

    @Operation(summary = "获取销售报表信息", description = "参数为商品名称")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end,
                                  @RequestParam(required = false) String goodsName) {
        PageInfo pageInfo = tradeSaleService.getPage(pageNum, pageSize, start, end, goodsName);
        return ResponseResult.okResult(pageInfo);
    }

    /**
     * 上传入库文件excel表格
     *
     * @param multipartFile
     * @return
     */
    @Operation(summary = "上传销售报表", description = "参数为导入选择的时间")
    @PostMapping("/upload")
    public ResponseResult upload(@RequestParam(value = "file") MultipartFile multipartFile,
                                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        Boolean flag = tradeSaleService.upload(multipartFile, start, end);
        return ResponseResult.okResult(flag?"刷新成功":"正在刷新中。。。");
    }
}

